﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;

namespace ERPStore.Web.Cart.Controllers
{
	public class AdminCartApiController : ApiController
	{
		public AdminCartApiController(ERPStore.Cart.Services.CartService cartService
			, ERPStore.Cart.Services.AdminCartService adminCartService
			, ERPStore.Services.ICatalogService catalogService
			, ERPStore.Services.IOffersService offerService
			, ERPStore.Services.IIncentiveService incentiveService
			, ERPStore.Services.IAccountService accountService
			, ERPStore.Services.ISalesService salesService
			, ERPStore.Logging.ILogger logger
			)
		{
			this.CartService = cartService;
			this.AdminCartService = adminCartService;
			this.CatalogService = catalogService;
			this.OfferService = offerService;
			this.IncentiveService = incentiveService;
			this.AccountService = accountService;
			this.SalesService = salesService;
			this.Logger = logger;
		}

		protected ERPStore.Cart.Services.CartService CartService { get; private set; }
		protected ERPStore.Cart.Services.AdminCartService AdminCartService { get; private set; }
		protected ERPStore.Services.ICatalogService CatalogService { get; private set; }
		protected ERPStore.Services.IOffersService OfferService { get; private set; }
		protected ERPStore.Services.IIncentiveService IncentiveService { get; private set; }
		protected ERPStore.Services.IAccountService AccountService { get; private set; }
		protected ERPStore.Services.ISalesService SalesService { get; private set; }
		protected ERPStore.Logging.ILogger Logger { get; private set; }

		[HttpGet]
		public DateTime Ping()
		{
			return DateTime.Now;
		}

		[ERPStore.Web.Controllers.ActionFilters.ApiAuthorizedOperation]
		[System.Web.Http.HttpPost]
		public ERPStore.Cart.Models.OrderCartExtendedListResult GetOrderCartList(ERPStore.Cart.Models.OrderCartFilter filter)
		{
			var result = new ERPStore.Cart.Models.OrderCartExtendedListResult();

			var count = 0;
			var list = AdminCartService.GetOrderCartListByFilter(filter, out count);
			result.List = AutoMapper.Mapper.Map<List<ERPStore.Cart.ViewModels.CartViewModel>>(list);
			result.TotalCount = count;

			return result;
		}

		[ERPStore.Web.Controllers.ActionFilters.ApiAuthorizedOperation]
		[System.Web.Http.HttpGet]
		public string ConvertToOrder(string id)
		{
			var orderCode = AdminCartService.ConvertToOrder(id);
			return orderCode;

		}

	}
}
